#!/bin/tcsh -ef
#############################################################################
#                                                                           #
# Title: Particle Picking (NOT READY TO USE)                                #
#                                                                           #
# (C) 2dx.org, GNU Plublic License.                                         #
#                                                                           #
# Created..........: 05/19/2007                                             #
# Last Modification: 05/19/2007                                             #
# Author...........: 2dx.org                                                #
#                                                                           #
#############################################################################
#
# SORTORDER: 40
#
#$end_local_vars
#
# MANUAL: Single Particle Refinement (still under construction)
#
# DISPLAY: particle_size_sp2dx
# DISPLAY: invert_sp2dx
# DISPLAY: maximum_mag_sp2dx
# DISPLAY: symmetry_sp2dx
# DISPLAY: is_glpf_sp2dx
# DISPLAY: cont_folder_sp2dx
# DISPLAY: cont_sx_sp2dx
# DISPLAY: binn_sp2dx
# DISPLAY: double_pick_sp2dx
# DISPLAY: minstd_pick_sp2dx
#
# DISPLAY: local_ctf_sp2dx
# DISPLAY: local_ctf_ampcon_sp2dx
# DISPLAY: hist_equal_sp2dx
# DISPLAY: sym_inplane_sp2dx
# DISPLAY: max_inplane_tltang_sp2dx
# DISPLAY: particle_selection_method_pick_sp2dx
# DISPLAY: number_particles_pick_sp2dx
# DISPLAY: percent_particles_pick_sp2dx
# DISPLAY: particle_masking_sp2dx
# DISPLAY: particle_masking_params_sp2dx
# DISPLAY: hp_particle_filter_sp2dx
#
#
#
set bin_2dx = ""
set proc_2dx = ""
#
set particle_size_sp2dx = ""
set invert_sp2dx = ""
set maximum_mag_sp2dx = ""
set symmetry_sp2dx = ""
set is_glpf_sp2dx = ""
set binn_sp2dx = ""
set double_pick_sp2dx = ""
set minstd_pick_sp2dx = ""
set cont_sx_sp2dx = ""
#
set local_ctf_sp2dx = ""
set local_ctf_ampcon_sp2dx = ""
set hist_equal_sp2dx = ""
set sym_inplane_sp2dx = ""
set max_inplane_tltang_sp2dx = ""
set particle_selection_method_pick_sp2dx = ""
set number_particles_pick_sp2dx = ""
set percent_particles_pick_sp2dx = ""
set particle_masking_sp2dx = ""
set particle_masking_params_sp2dx = ""
set hp_particle_filter_sp2dx = ""
set cont_folder_sp2dx = ""
#
#$end_vars

echo "<<@progress: 1>>"

set scriptname = SingleParticle_Picking

set particle_selection_method_incharge = $particle_selection_method_pick_sp2dx
set number_particles_incharge = $number_particles_pick_sp2dx
set percent_particles_incharge = $percent_particles_pick_sp2dx

\rm -f LOGS/${scriptname}.results
echo "<<@evaluate>>"


source ${proc_2dx}/2dx_makedirs 
\rm -f SCRATCH/2dx_merge_dirfile_oneline.dat
\rm -f SCRATCH/2dx_SP_convergence.txt
\rm -f SCRATCH/2dx_SP_convergence_tree.txt
\rm -f container_stat.txt

cat 2dx_merge_dirfile.dat | tr "\n" " " > SCRATCH/2dx_merge_dirfile_oneline.dat
set dirlist = "`cat SCRATCH/2dx_merge_dirfile_oneline.dat`"
#set dirstack = `pwd`
#echo $dirstack

echo "set called now"
#rm mergevars_written_to_file.txt
set > mergevars_written_to_file.txt

set olddir = `pwd`

foreach dirfile (${dirlist}) 
	echo "::Extracting profile in ${dirfile}"
	cd ../${dirfile}
	cp `ls -1 *.gz` cc_profile.dat.gz
	gunzip -f cc_profile.dat.gz
	#ls *.mrc
	cd ${olddir}
end


${bin_2dx}/2dx_singleparticle/PickParticleContainer.exe

python ${bin_2dx}/2dx_singleparticle/image_plotter_sim.py "$cont_folder_sp2dx/ContainerStatsTXT/original.txt" "$cont_folder_sp2dx/ContainerStatsPDF/original.pdf"

python ${bin_2dx}/2dx_singleparticle/image_output_2dx_absolut_path.py "$cont_folder_sp2dx/ContainerStatsPDF/original.pdf" "Container Stat" "$scriptname" 1

echo "<<@progress: 100>>"

